﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace SZSLSystem.DAL
{
	/// <summary>
	///数据访问类 RoomImage (create by HC 2013/1/14 22:28:42)
	/// </summary>
	public class RoomImage
	{
		public RoomImage(){}
		public bool Exists(string OID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select count(OID) from RoomImage");
			strSql.Append(" where OID=@OID ");
			SqlParameter[] parameters = {
					new SqlParameter ("@OID",SqlDbType.VarChar,50)};
			parameters[0].Value = OID;

			return DbHelperOleDb.Exists(strSql.ToString(), parameters);
		}

		public int Delete(string OID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("delete from RoomImage");
			strSql.Append(" where OID=@OID  ");
			SqlParameter[] parameters = {
					new SqlParameter ("@OID",SqlDbType.VarChar,50)};
			parameters[0].Value = OID;

			return DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
		}

		public int Add(SZSLSystem.Model.RoomImage model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into RoomImage( ");
			strSql.Append("[OID],[RoomImageType],[RoomImageName],[LargerImagePath],[SmallImagePath])");
			strSql.Append("values (@OID,@RoomImageType,@RoomImageName,@LargerImagePath,@SmallImagePath)");
			SqlParameter[] parameters = {
					new SqlParameter ("@OID",SqlDbType.VarChar,50),
					new SqlParameter ("@RoomImageType",SqlDbType.VarChar,50),
					new SqlParameter ("@RoomImageName",SqlDbType.VarChar,50),
					new SqlParameter ("@LargerImagePath",SqlDbType.VarChar,500),
					new SqlParameter ("@SmallImagePath",SqlDbType.VarChar,500)};
			parameters[0].Value = model.OID;
			parameters[1].Value = model.RoomImageType;
			parameters[2].Value = model.RoomImageName;
			parameters[3].Value = model.LargerImagePath;
			parameters[4].Value = model.SmallImagePath;
			object obj = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
			if (obj == null)
			{
				return 1;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}

		public  SZSLSystem.Model.RoomImage GetModel(string OID)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select top 1 [OID],[RoomImageType],[RoomImageName],[LargerImagePath],[SmallImagePath] from RoomImage");
			strSql.Append(" where OID=@OID ");
			SqlParameter[] parameters = {
					new SqlParameter ("@OID",SqlDbType.VarChar,50)};
			parameters[0].Value = OID;

			SZSLSystem.Model.RoomImage model=new SZSLSystem.Model.RoomImage();
			DataSet ds=DbHelperOleDb.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				DataRow row = ds.Tables[0].Rows[0];
						model.OID=row["OID"].ToString();
						model.RoomImageType=row["RoomImageType"].ToString();
						model.RoomImageName=row["RoomImageName"].ToString();
						model.LargerImagePath=row["LargerImagePath"].ToString();
						model.SmallImagePath=row["SmallImagePath"].ToString();

				return model;
			}
			else
			{
				return null;
			}
		}

		public int Update(SZSLSystem.Model.RoomImage model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("update RoomImage set ");
			strSql.Append("[OID]=@OID,");
			strSql.Append("[RoomImageType]=@RoomImageType,");
			strSql.Append("[RoomImageName]=@RoomImageName,");
			strSql.Append("[LargerImagePath]=@LargerImagePath,");
			strSql.Append("[SmallImagePath]=@SmallImagePath");
			strSql.Append(" where OID=@OID ");
			SqlParameter[] parameters = {
					new SqlParameter ("@OID",SqlDbType.VarChar,50),
					new SqlParameter ("@RoomImageType",SqlDbType.VarChar,50),
					new SqlParameter ("@RoomImageName",SqlDbType.VarChar,50),
					new SqlParameter ("@LargerImagePath",SqlDbType.VarChar,500),
					new SqlParameter ("@SmallImagePath",SqlDbType.VarChar,500)};
			parameters[0].Value = model.OID;
			parameters[1].Value = model.RoomImageType;
			parameters[2].Value = model.RoomImageName;
			parameters[3].Value = model.LargerImagePath;
			parameters[4].Value = model.SmallImagePath;

			return DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);
		}

		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select [OID],[RoomImageType],[RoomImageName],[LargerImagePath],[SmallImagePath]");
			strSql.Append(" FROM RoomImage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOleDb.Query(strSql.ToString());
		}

		public DataSet GetList(int top,string strWhere,string fieldOrder)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("select");
			if(top>0)
			{
				strSql.Append(" top "+top.ToString());
			}
			strSql.Append(" [OID],[RoomImageType],[RoomImageName],[LargerImagePath],[SmallImagePath]");
			strSql.Append(" FROM RoomImage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
				strSql.Append(" order by "+fieldOrder);
			return DbHelperOleDb.Query(strSql.ToString());
		}

		public DataSet GetList(string showFields,string strWhere)
		{
			StringBuilder strSql = new StringBuilder();
				strSql.Append(" select "+showFields);
			strSql.Append(" FROM RoomImage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOleDb.Query(strSql.ToString());
		}

		public object GetSingle(string fieldName,string strWhere)
		{
			StringBuilder strSql = new StringBuilder();
				strSql.Append(" select "+fieldName);
			strSql.Append(" FROM RoomImage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOleDb.GetSingle(strSql.ToString());
		}

	}
}